package cn.edu.fzu.homemaking.company.controller;

import cn.edu.fzu.homemaking.common.SessionConstant;
import cn.edu.fzu.homemaking.company.api.SysApi;
import cn.edu.fzu.homemaking.company.domain.entity.CompanyUser;
import cn.edu.fzu.homemaking.company.domain.enums.LabelStatusEnum;
import cn.edu.fzu.homemaking.web.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author wanjie
 * @version 1.0
 */
@RestController
@RequestMapping("/api/company/auth/label")
@Api(tags = "Label相关接口")
public class LabelController {
    @Resource
    private SysApi sysApi;

    //展示所有的标签
    @GetMapping("/list")
    @ApiOperation(value = "标签列表", httpMethod = "GET")
    @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "标签名字") })
    @ApiResponse(code = 200, message = "", response = Result.class)
    public Result listLabel(String name) {
        return sysApi.listLabels(name, LabelStatusEnum.NORMAL);
    }


    @ApiOperation(value = "获取公司的标签")
    @ApiImplicitParams({@ApiImplicitParam(name = "pageNum", required = false, value = "页码（不填返回全部数据）"),
            @ApiImplicitParam(name = "pageSize", required = false, value = "页面大小（不填返回全部数据）") })
    @GetMapping("/getByCompany")
    public Result getByCompanyId(Integer pageNum, Integer pageSize, HttpServletRequest request) {
        CompanyUser user = (CompanyUser) request.getSession().getAttribute(SessionConstant.ACCOUNT);
        return sysApi.getByCompanyId(user.getCompany().getId(), pageNum, pageSize);
    }
}
